package com.zx.zxpicture.infrstructure.config;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.BasicSessionCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.region.Region;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 腾讯云对象存储客户端
 *
 * @author <a href="https://github.com/liyupi">程序员鱼皮</a>
 * @from <a href="https://yupi.icu">编程导航知识星球</a>
 */
@Configuration
@ConfigurationProperties(prefix = "cos.client")
@Data
public class CosClientConfig {
    private String host;
    private String secretId;
    private String secretKey;
    private String region;
    private String bucket;

    @Bean
    public COSClient createCosClient(){
        BasicCOSCredentials basicCOSCredentials = new BasicCOSCredentials(secretId, secretKey);
        // 2 设置 bucket 的地域
        Region region1 = new Region(region);
        ClientConfig clientConfig = new ClientConfig(region1);
        // 3 生成 cos 客户端
        return new COSClient(basicCOSCredentials, clientConfig);
    }
}